<?php

require_once 'src/model/mPet.php';

class aPet extends mPet {
    /* datefomat ver data alua 06 
     * mysql : date_format(data_cad, '%s') as data_cad
     */
    protected $sqlInsert = "INSERT INTO pet(nome, especie, raca, peso, dtnasc, idcliente) VALUES ('%s','%s','%s','%s','%s','%s')";
    protected $sqlUpdate = "UPDATE pet SET nome='%s',especie='%s',raca='%s',peso='%s',dtnasc='%s',idcliente='%s' WHERE idpet = '%s'";
    protected $sqlSelect = "SELECT * FROM pet WHERE 1=1 %s %s";
    protected $sqlDelete = "DELETE FROM pet WHERE idpet = '%s'";

    public function insert() {
        $sql = sprintf($this->sqlInsert, $this->getNome(), $this->getEspecie(), 
                $this->getRaca(), $this->getPeso(), $this->getDtnasc(),
                $this->getIdcliente());
        return $this->RunQuery($sql);
    }

    public function update() {
        $sql = sprintf($this->sqlUpdate, $this->getNome(), $this->getEspecie(), 
                $this->getRaca(), $this->getPeso(), $this->getDtnasc(), 
                $this->getIdcliente(), $this->getIdpet());
        return $this->RunQuery($sql);
    }

    public function delete() {
        $sql = sprintf($this->sqlDelete, $this->getIdpet());
        return $this->RunQuery($sql);
    }
    
    public function select($where='', $order='') {
        $sql = sprintf($this->sqlSelect, $where, $order);
        return $this->RunSelect($sql);
    }    
    
    public function load() {
        $rs = $this->select(sprintf("and idpet='%s'", $this->getIdpet()));
        $this->setIdcliente($rs[0]['idpet']);
        $this->setNome($rs[0]['nome']);
        $this->setEspecie($rs[0]['especie']);
        $this->setRaca($rs[0]['raca']);
        $this->setPeso($rs[0]['peso']);
        $this->setDtnasc($rs[0]['dtnasc']);
        $this->setIdcliente($rs[0]['idcliente']);
        return $this;
    }
    
}
